<template>
<div class="user">
    <!--搜索表单-->
    <div class="common-seach-wrap">
      <el-form
        size="small"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item :label="$t('plus.member_info')">
          <el-input
            clearable
            v-model="formInline.nickName"
            :placeholder="$t('plus.input_user_nickname')"
          ></el-input>
        </el-form-item>
        <el-form-item :label="$t('plus.checkin_time')">
          <div class="block">
            <span class="demonstration"></span>
            <el-date-picker
              size="small"
              v-model="formInline.createTime"
              type="daterange"
              value-format="YYYY-MM-DD"
              :range-separator="$t('plus.to')"
              :start-placeholder="$t('plus.start_date')"
              :end-placeholder="$t('plus.end_date')"
            >
            </el-date-picker>
          </div>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="Search" @click="onSubmit"
            >{{$t('plus.search')}}</el-button
          >
        </el-form-item>
      </el-form>
    </div>

    <div class="product-content">
      <el-form ref="form" :model="form" label-width="100px">
        <div class="table-wrap">
          <el-table
            size="small"
            :data="tableData"
            border
            style="width: 100%"
            v-loading="loading"
          >
            <el-table-column prop="userId" label="ID"></el-table-column>
            <el-table-column prop="nickName" :label="$t('plus.member_info')"></el-table-column>
            <el-table-column
              prop="minDate"
              :label="$t('plus.first_checkin')"
            ></el-table-column>
            <el-table-column
              prop="lastDate"
              :label="$t('plus.last_checkin')"
            ></el-table-column>
            <el-table-column
              prop="maxDate"
              :label="$t('plus.final_checkin')"
            ></el-table-column>
            <el-table-column
              prop="totalDay"
              :label="$t('plus.total_checkins')"
            ></el-table-column>
            <el-table-column
              prop="continuousDays"
              :label="$t('plus.max_checkin_days')"
            ></el-table-column>
            <el-table-column prop="prize" :label="$t('plus.checkin_rewards')">
              <template #default="scope">
                <div>
                  {{$t('plus.points_reward_placeholder',{place1:scope.row.points})}} 
<div v-for="(item, index) in scope.row.coupon" :key="index">
                    <text class="orange">{{item.name}}</text> x{{item.couponNum}}; 


</div>
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-form>
      <!--分页-->
      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          :current-page="curPage"
          :page-size="pageSize"
          layout="total, prev, pager, next, jumper"
          :total="totalDataNumber"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import SignApi from "@/api/sign.js";
import { formatDate } from "@/utils/DateTime.js";
export default {
  data() {
    return {
      formInline: {
        nickName: "",
        createTime: []
      },
      form: {},
      tableData: [],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*是否加载完成*/
      loading: true,
      /*搜索条件*/
      daysList: [$t("plus.days_2"), $t("plus.days_3"), $t("plus.days_4"), $t("plus.days_5"), $t("plus.days_6"), $t("plus.days_7"), $t("plus.days_15"), $t("plus.days_30"), $t("plus.days_60")],
      /*搜索条件*/
      signTime: [$t("plus.recent_7_days"), $t("plus.recent_15_days"), $t("plus.recent_30_days"), $t("plus.custom")]
    };
  },
  created() {
    /*获取列表*/
    this.getData();
  },
  methods: {
    /*获取列表*/
    getData() {
      let self = this;
      let Params = {};
      Params.pageIndex = self.curPage;
      Params.pageSize = self.pageSize;
      SignApi.getSignList(Params, true).then(res => {
        self.loading = false;
        self.tableData = res.data.records;
        self.totalDataNumber = res.data.total;
      }).catch(error => {});
    },
    onSubmit() {
      let self = this;
      let Params = {};
      Params.startDate = self.formInline.createTime[0];
      Params.endDate = self.formInline.createTime[1];
      Params.nickName = self.formInline.nickName;
      Params.pageIndex = self.curPage;
      Params.pageSize = self.pageSize;
      self.loading = true;
      SignApi.getSignList(Params, true).then(data => {
        self.loading = false;
        self.tableData = data.data.records;
        self.totalDataNumber = data.data.total;
      }).catch(error => {});
    },
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.curPage = val;
      self.loading = true;
      self.getData();
    },
    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getData();
    }
  }
};
</script>

